import { request, qs } from "../service";

const dictInfo = {
  /**
   * 查找字典列表
   */
  list(param) {
    return request({
      url: '/auth/dict/list',
      method: 'get',
      params: addDefaultParam(param)
    })
  },

  /**
   * 查找字典总数
   */
  count(param) {
    return request({
      url: '/auth/dict/count',
      method: 'get',
      params: addDefaultParam(param)
    })
  },

  /**
   * 添加字典
   */
  add(param) {
    return request({
      url: '/auth/dict/add',
      method: 'post',
      data: addDefaultParam(param)
    });
  },

  /**
   * 更新字典
   */
  update(param) {
    return request({
      url: '/auth/dict/update',
      method: 'put',
      data: addDefaultParam(param)
    });
  },

  /**
   * 删除字典
   */
  delete(id) {
    return request({
      url: '/auth/dict/delete/' + id,
      method: 'delete'
    });
  },

  /**
   * 批量删除字典
   */
   deleteBatch(param) {
    return request({
      url: `/auth/dict/deleteBatch`,
      method: 'delete',
      params: param,
      paramsSerializer: params => {
        return qs.stringify(params, {
          indices: false
        })
      }
    })
  },
}

/**
 * 添加缺省参数值
 * @param {*} param 原始参数
 * @returns 携带缺省参数返回
 */
function addDefaultParam(param) {
  let params = param;
  params['app'] = process.env.VUE_APP_SYSTEM_NAME;
  return params;
}

export default dictInfo;
